<template>
    <div style="width:100px;height:200px;">
        <!-- <el-input style="opacity: 0;" id="infoId" type="text" size="100" value=''>
        </el-input> -->
        <!-- <table style="width:100%;" border="5" valign="bottom">
            <tr id="trInfo" style="height:30">
                <td>
                    <form name="formname">
                        文件路径：<input id="fileurl" type=text value="C:\Program Files (x86)\sursen\ofdsuite\readme .ofd"
                            size=50 />
                        <input type="radio" id="fileReadOnly" name="fileReadOnly" value="false" checked="checked">可编辑，<input
                            type="radio" id="fileReadOnly" name="fileReadOnly" value="true">只读
                        <br><br>
                        <el-input type=button value="1.加载阅读器组件" @click="initOFD()" />&nbsp;&nbsp;
                        <input type=button value="2.打开文档" onclick="openFile()" @click="openFile()" />&nbsp;&nbsp;
                        <input type=button value="3.打印文件" onclick="printFile()" />&nbsp;&nbsp;
                        <input type=button value="4.关闭文档" onclick="closeFile()" />



                    </form>
                </td>
            </tr>
            <tr>
                <td></td>
            </tr>
            <tr></tr>
        </table> -->
        <div ref="ofdArea" id="ofdDiv" style="width:100%;height:100%"></div>
    </div>
</template>
<script>

// import ofdPlugin from '@/utils/sursenread.js';
import { sydm } from "@/api/archive/fileCollection/offlinReception.js";
import {minusOne, minusOnePrint} from "@/api/archive/archiveBorrow/archiveBorrow";
import { isType } from 'pdf-lib';
export default {
    data() {
        return {
            synr: ""
        }
    },
    props: ["ofdUrl", "borrowItemId"],
    watch: {
        ofdUrl: {
            handler(valNew, valOld) {
                var that = this;
                console.log(this.borrowItemId, "0000000000000000000000000liuh")
                // debugger;
                // 数据加载完成后将dataLoaded设为true
                that.$modal.loading("正在预览文件，请稍候...")
                setTimeout(res => {
                    // console.log(valNew, this.$refs["ofdArea"], document.getElementById("ofdDiv"), "111111111111111111")
                    // const divID = 'ofdArea';
                    const width = 500;
                    const height = 300;
                    // var ofd = {};
                    if (this.isIE()) {
                        document.getElementById("ofdDiv").innerHTML = "<OBJECT ID='sursenofd' CLASSID='CLSID:A18E7987-900A-4c32-B0B9-B4C1BEDB5DDD' WIDTH='100%' HEIGHT='100%'></OBJECT>";
                    } else {
                        //firefox
                        document.getElementById("ofdDiv").innerHTML = "<embed id='sursenofd' TYPE='trivial/very'  WIDTH='100%' HEIGHT='100%' text='' print='1' EleSeal='1' WriteString=''></embed>";
                    }
                    sydm({
                        sydm: "yulan"
                    }).then(res => {
                        // console.log(res.data.synr, "水印")
                        this.synr = res.data.synr;
                        // const url = URL.createObjectURL(valNew);
                        //console.log(valNew,"+++++++++++++++++++++++")
                        //var data= url.substring(5,url.length)
                        //const url="/home/kingbase/桌面/aaa.ofd"
                        const url = window.location.protocol + '//' + window.location.host + process.env.VUE_APP_BASE_API + `/archive/detail/viewOfd?token=` + valNew
                        // console.log(url)
                        that.$modal.closeLoading()
                        if (this.borrowItemId != undefined) { //是否有借阅ID 都的换判断打印次数
                            minusOnePrint(this.borrowItemId).then(res => {
                                if (res.code == '601') {
                                    console.log("601")
                                    this.datainfo(url,false)
                                    // this.$modal.msgWarning(res.msg)
                                } else {
                                    //TODO 调用打印方法打印文件
                                    this.datainfo(url,true)
                                }
                            })
                        } else {
                            this.datainfo(url,true)
                        }
                        // console.log(document.getElementById("sursenofd"),"==========================获取sursenofd")
                    

                        //
                        // var ofd = this.initReader(divID, width, height, url);

                        // console.log(url, "______________________")
                        // // var data= url.substring(5,url.length)
                        // // console.log( data,"data")
                        // this.openFile(ofd, url)
                    })



                }, 1000)




            },
            immediate: true,
        }
    },
    created() {

    },
    methods: {
        datainfo(url,isType){
            if(!isType){
                document.getElementById("TrivialObject").setCompositeEnable('f_print', isType); //是否禁用打印功能
            }
          
                        document.getElementById("sursenofd").openFile(url, false);

                        // var infoId = document.getElementById("infoId").value;
                        var data = '<?xml version="1.0" encoding="UTF-8"?>'
                            + '<setinfo type="barinfo">'
                            + '<parameter name="pages" value="1-2000"/>'
                            + '<parameter name="rotate" value="0"/>'
                            + '<parameter name="visible" value="true"/>'
                            + '<parameter name="printable" value="true"/>'
                            + '<parameter name="xpostype" value="absolute"/>'
                            + '<parameter name="ypostype" value="absolute"/>'
                            + '<parameter name="x" value="10"/>'
                            + '<parameter name="y" value="10"/>'
                            + '<parameter name="w" value="100"/>'
                            + '<parameter name="h" value="20"/>'
                            + '<parameter name="strcont" font="仿宋" size="48" opaque="true" color="DCDFE6" >' + res.data.synr + '</parameter>'
                            + '</setinfo>'


                        document.getElementById("sursenofd").addTrackInfo(data);
        },

        isIE() {
            return !!window.ActiveXObject || 'ActiveXObject' in window;
        },
    }
}
</script>
